package com.jeeplus.modules.work.utils;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;

import com.tencentcloudapi.faceid.v20180301.FaceidClient;

import com.tencentcloudapi.faceid.v20180301.models.DetectAuthRequest;
import com.tencentcloudapi.faceid.v20180301.models.DetectAuthResponse;
import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoRequest;
import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoResponse;
import net.sf.json.JSONObject;

public class CheckFace {
    //获取人脸认证信息
    public static String getCheckFaceUrl(String SecretId, String SecretKey,String resultUrl,String url) {
        try {
            Credential cred = new Credential(SecretId, SecretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("faceid.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            FaceidClient client = new FaceidClient(cred, "ap-chengdu", clientProfile);
            String params = "{\"RedirectUrl\":\""+resultUrl+"\",\"RuleId\":\"1\",\"Extra\":\""+url+"\"}";
            DetectAuthRequest req = DetectAuthRequest.fromJsonString(params, DetectAuthRequest.class);
            DetectAuthResponse resp = client.DetectAuth(req);
            return DetectAuthRequest.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
            return null;
        }
    }

    //查询人脸认证信息返回结果
    public static String GetDetectInfo(String SecretId, String SecretKey,String BizToken) {

        try{
            Credential cred = new Credential(SecretId, SecretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("faceid.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            FaceidClient client = new FaceidClient(cred, "ap-chengdu", clientProfile);
            String params = "{\"BizToken\":\""+BizToken+"\",\"RuleId\":\"1\"}";
            GetDetectInfoRequest req = GetDetectInfoRequest.fromJsonString(params, GetDetectInfoRequest.class);
            GetDetectInfoResponse resp = client.GetDetectInfo(req);
            return GetDetectInfoRequest.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
            return null;
        }
    }
}
